package com.liuguangzhou.controller;

import org.springframework.web.bind.annotation.*;

/**
 * @ClassName TestController
 * @Description: TODO
 * @Author liuguangzhou
 * @Date 2020/3/14
 * @Version V1.0
 **/

@RestController
@RequestMapping("/test")
public class TestController {


    /**
    * 功能描述:
    * 〈这样写  访问test和 testCopy都可以进来 GET POST方法都支持〉
    * @Param: []
    * @Return: void
    * @Author: liuguangzhou
    * @Date: 2020/3/14 19:43
    */
    @RequestMapping(value ={"test","testCopy"},method = {RequestMethod.GET,RequestMethod.POST})
    public void test(){
        System.out.println("test方法");
    }



    //    params是规定请求时必须指定的参数名和参数值
    //    代码例子:代表请求时,必须带有name参数，并且值也必须是admin

    @RequestMapping(params = "name=admin")
    public void test1(){
        System.out.println("test1方法");
    }



    //@RequestParam 请求时参数不能为空  但参数值可以任意
    @RequestMapping("/login")
    public void test2(@RequestParam String name, @RequestParam String password){
        System.out.println("test2方法");
    }


    //headers规定 请求时必须有消息头信息
    @RequestMapping(value = "headers",headers = "content-type=text/html")
    public void headers(){
        System.out.println("headers  html方法");
    }

    @RequestMapping(value = "headers",headers = "content-type=text/xml")
    public void headers1(){
        System.out.println("headers  xml方法");
    }



    /**
    * 消费   相当于规定了浏览器穿什么信息过来 相当于配置了 headers = "content-type=text/xml
    */
    @RequestMapping(value = "consumes",consumes = "text/html")
    public void consumes(){
        System.out.println("consumes  html方法");
    }

    @RequestMapping(value = "consumes",consumes = "text/xml")
    public void consumes1(){
        System.out.println("consumes  xml方法");
    }




    //生产者   返回指定的数据  相当于配置了 headers = "Accept=text/xml
    @RequestMapping(value = "produces",produces = "text/html")
    public void produces(){
        System.out.println("produces  html方法");
    }

    @RequestMapping(value = "produces",produces = "text/xml")
    public void produces1(){
        System.out.println("produces  xml方法");
    }



    //不加@RequestBody 注解post get方法只能接受到参数 要是APP给发送消息 是json xml就收不到
    //需要这个注解 可以把请求体内容封装到对象中

//    @RequestMapping("employee")
//    public void test2(@RequestBody Employee employee){
//        System.out.println(employee);
//    }
    @RequestMapping("employee")
    public void test2(@RequestBody String employee){
        System.out.println(employee);
    }


}
